#include "board.h"
#include "time.h"

void time_init(void)
{
}

//获取计时器运行时间(ms),最大测量时间：5ms
float time_get_ms(uint32_t *thread_tick)
{
    uint32_t count,temp;

    count = MeasureGet();
    temp = SYS_TICKDIFF(*thread_tick,count);
    *thread_tick = count;
     
    return (float)(temp / MeasureFerquency);
}

#if 0

static void math_test(int num, char **p)
{
	char txt[128];
	int temp = atoi(p[1]);
	int vel = atoi(p[2]);
    static uint32_t tick = 0;
    volatile float angle = 0;

    tick = MeasureGet();
    for(int i = 0; i < 50; i++) {

        // angle = arm_sin_f32(temp);
        // angle = arm_cos_f32(temp);
        arm_atan2_f32((float)temp , (float)vel, &angle); // 示例调用
        (void)angle; // 防止编译器优化掉

    }
	sprintf((char*)txt,"time:%f,test:%d / %d,result:%f\n",time_get_ms(&tick),temp,vel,angle);
	rt_kprintf("%s",txt);

    tick = MeasureGet();
    for(int i = 0; i < 50; i++) {

        // angle = sinf(temp);
        // angle = cosf(temp);
        angle = atan2f((float)temp , (float)vel); // 示例调用
        (void)angle; // 防止编译器优化掉

    }
	sprintf((char*)txt,"time:%f,test:%d / %d,result:%f\n",time_get_ms(&tick),temp,vel,angle);
	rt_kprintf("%s",txt);
}
MSH_CMD_EXPORT(math_test, math_test);

#endif
